<template>
  <d2-container>
    <template slot="header">设置切片</template>
    <el-form
      :inline="true"
      :model="slice_configuration"
      class="demo-form-inline"
    >
      <el-form-item label="bs_id">
        <el-input v-model="bs_id" placeholder="bs_id"></el-input>
      </el-form-item>
      <br />UL Parameters<br />
      <el-form-item label="algorithm">
        <el-select
          v-model="slice_configuration.ul.algorithm"
          placeholder="algorithm"
        >
          <el-option label="None" value="None"></el-option>
          <el-option label="Static" value="Static"></el-option>
        </el-select>
        <el-form-item label=" slices_id">
          <el-input
            v-model="slice_configuration.ul.slices[0].id"
            placeholder="1~255"
          ></el-input>
        </el-form-item>
      </el-form-item>
      <el-form-item label=" slice_static">
        <el-input
          v-model="slice_configuration.ul.slices[0].static.posLow"
          placeholder="posLow"
        ></el-input>
        <el-input
          v-model="slice_configuration.ul.slices[0].static.posHigh"
          placeholder="posHigh"
        ></el-input>
      </el-form-item>
      <br />DL Parameters<br />
      <el-form-item label="algorithm">
        <el-select
          v-model="slice_configuration.dl.algorithm"
          placeholder="algorithm"
        >
          <el-option label="None" value="None"></el-option>
          <el-option label="Static" value="Static"></el-option>
        </el-select>
        <el-form-item label=" slices_id">
          <el-input
            v-model="slice_configuration.dl.slices[0].id"
            placeholder="1~255"
          ></el-input>
        </el-form-item>
      </el-form-item>
      <el-form-item label=" slice_static">
        <el-input
          v-model="slice_configuration.dl.slices[0].static.posLow"
          placeholder="posLow"
        ></el-input>
        <el-input
          v-model="slice_configuration.dl.slices[0].static.posHigh"
          placeholder="posHigh"
        ></el-input>
      </el-form-item>
      <br />
      <el-form-item>
        <el-button type="primary" @click="onSubmit">submit</el-button>
        <el-button type="primary" @click="ueSlice1">association1</el-button>
        <el-button type="primary" @click="ueSlice2">association2</el-button>
        <el-button type="primary" @click="Auto">auto</el-button>
      </el-form-item>
    </el-form>
  </d2-container>
</template>

<script>
import Axios from "axios";
export default {
  name: "page3",
  data() {
    return {
      bs_id: "-1",
      slice_configuration: {
        ul: {
          algorithm: "Static",
          slices: [
            {
              id: 2,
              static: {
                posLow: 0,
                posHigh: 3,
              },
            },
          ],
        },
        dl: {
          algorithm: "Static",
          slices: [
            {
              id: 0,
              static: {
                posLow: 4,
                posHigh: 12,
              },
            },
          ],
        },
      },
    };
  },
  classres() {
    return {
      data:
        //先给data对象为空
        [{}],
      //树形控件需要配置的默认信息，与json匹配
      defaultProps: {
        children: "childs",
        label: "name",
      },
    };
  },
  methods: {
    ueSlice1() {
      const data = {
        ueConfig: [
          {
            imsi: 208930100000146,
            dlSliceId: 0,
            ulSliceId: 0,
          },
        ],
      };
      Axios({
        method: "post",
        url: "/api/ue_slice_assoc/enb/" + this.bs_id,
        data,
      }).then((res) => {
        console.log(res.data);
      });
    },
    ueSlice2() {
      const data = {
        ueConfig: [
          {
            imsi: 208930100000139,
            dlSliceId: 0,
            ulSliceId: 0,
          },
        ],
      };
      Axios({
        method: "post",
        url: "/api/ue_slice_assoc/enb/" + this.bs_id,
        data,
      }).then((res) => {
        console.log(res.data);
      });
    },
    onSubmit() {
      let data = {
        ul: {},
        dl: {},
      };
      if (this.slice_configuration.ul.algorithm === "None") {
        data.ul = {
          algorithm: "None",
        };
      } else {
        data.ul = this.slice_configuration.ul;
      }
      if (this.slice_configuration.dl.algorithm === "None") {
        data.dl = {
          algorithm: "None",
        };
      } else {
        data.dl = this.slice_configuration.dl;
      }
      console.log(data);
      Axios({
        method: "post",
        url: "/api/slice/enb/" + this.bs_id,
        data,
      }).then((res) => {
        console.log(res.data);
        if (res.data.status === "Ok") {
          this.$message({
            message: "提交成功",
            type: "success",
          });
        }
      });
    },
    // set_charts(data) {
    //   Axios({
    //     method:"post",
    //     url:"/api/slice/enb/" + this.bs_id,
    //     data
    //   }).then((res)=>{

    //   })
    // }
      
     
            

          

    },
    Auto() {
      
      
     
    console.log('test');
    Axios.get('/slice_apis/get_data').then((res) =>{
      console.log(res.data)
      // this.set_charts(res.data)
    });
    

     
    },
  
};
</script>
